From: Kalev Lember Date: Wed, 19 Feb 2014 18:59:47 +0000 (+0100) Subject: endSessionDialog: Warn when trying to install updates on battery power X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~2730 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=46163a6607c55aa8c0ff5333c7ade123041705aa;p=gnome-shell.git endSessionDialog: Warn when trying to install updates on battery power Interrupting update installation can mess up the package database quite a bit and could lead to totally destroying the distro installtion. To avoid running out of juice during an upgrade, warn when someone tries to install updates on battery power. https://bugzilla.gnome.org/show_bug.cgi?id=722898 --- diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css index 35079d421..bb9ff5408 100644 --- a/data/theme/gnome-shell.css +++ b/data/theme/gnome-shell.css @@ -1966,6 +1966,19 @@ StScrollBar StButton#vhandle:active { text-align: right; } +.end-session-dialog-warning { + width: 28em; + color: #f57900; + padding-top: 6px; +} + +.end-session-dialog-warning:rtl { + width: 28em; + color: #f57900; + padding-top: 6px; + text-align: right; +} + .end-session-dialog-logout-icon { border: 2px solid #8b8b8b; border-radius: 5px; diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js index 5f06fc14d..2ac185efb 100644 --- a/js/ui/endSessionDialog.js +++ b/js/ui/endSessionDialog.js @@ -75,6 +75,7 @@ const logoutDialogContent = { "You will be logged out automatically in %d seconds.", seconds).format(seconds); }, + showBatteryWarning: false, confirmButtons: [{ signal: 'ConfirmedLogout', label: C_("button", "Log Out") }], iconStyleClass: 'end-session-dialog-logout-icon', @@ -90,6 +91,7 @@ const shutdownDialogContent = { seconds).format(seconds); }, checkBoxText: C_("checkbox", "Install pending software updates"), + showBatteryWarning: true, confirmButtons: [{ signal: 'ConfirmedReboot', label: C_("button", "Restart") }, { signal: 'ConfirmedShutdown', @@ -106,6 +108,7 @@ const restartDialogContent = { "The system will restart automatically in %d seconds.", seconds).format(seconds); }, + showBatteryWarning: false, confirmButtons: [{ signal: 'ConfirmedReboot', label: C_("button", "Restart") }], iconName: 'view-refresh-symbolic', @@ -121,6 +124,7 @@ const restartInstallDialogContent = { "The system will automatically restart and install updates in %d seconds.", seconds).format(seconds); }, + showBatteryWarning: true, confirmButtons: [{ signal: 'ConfirmedReboot', label: C_("button", "Restart & Install") }], iconName: 'view-refresh-symbolic', @@ -149,6 +153,14 @@ const LogindSessionIface = ' \ const LogindSession = Gio.DBusProxy.makeProxyWrapper(LogindSessionIface); +const UPowerIface = ' \ + \ + \ + \ +'; + +const UPowerProxy = Gio.DBusProxy.makeProxyWrapper(UPowerIface); + function findAppFromInhibitor(inhibitor) { let desktopFile; try { @@ -234,6 +246,19 @@ const EndSessionDialog = new Lang.Class({ this._updatesFile = Gio.File.new_for_path('/system-update'); this._preparedUpdateFile = Gio.File.new_for_path('/var/lib/PackageKit/prepared-update'); + this._powerProxy = new UPowerProxy(Gio.DBus.system, + 'org.freedesktop.UPower', + '/org/freedesktop/UPower', + Lang.bind(this, function(proxy, error) { + if (error) { + log(error.message); + return; + } + this._powerProxy.connect('g-properties-changed', + Lang.bind(this, this._sync)); + this._sync(); + })); + this._secondsLeft = 0; this._totalSecondsToStayOpen = 0; this._applications = []; @@ -284,6 +309,12 @@ const EndSessionDialog = new Lang.Class({ this._checkBox.actor.connect('clicked', Lang.bind(this, this._sync)); messageLayout.add(this._checkBox.actor); + this._batteryWarning = new St.Label({ style_class: 'end-session-dialog-warning', + text: _("Running on battery power: please plug in before installing updates.") }); + this._batteryWarning.clutter_text.ellipsize = Pango.EllipsizeMode.NONE; + this._batteryWarning.clutter_text.line_wrap = true; + messageLayout.add(this._batteryWarning); + this._scrollView = new St.ScrollView({ style_class: 'end-session-dialog-list' }); this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC); this.contentLayout.add(this._scrollView, @@ -337,6 +368,14 @@ const EndSessionDialog = new Lang.Class({ if (dialogContent.subjectWithUpdates && this._checkBox.actor.checked) subject = dialogContent.subjectWithUpdates; + if (dialogContent.showBatteryWarning) { + // Warn when running on battery power + if (this._powerProxy.OnBattery && this._checkBox.actor.checked) + this._batteryWarning.opacity = 255; + else + this._batteryWarning.opacity = 0; + } + let description; let displayTime = _roundSecondsToInterval(this._totalSecondsToStayOpen, this._secondsLeft, @@ -671,6 +710,12 @@ const EndSessionDialog = new Lang.Class({ this._checkBox.actor.visible = (dialogContent.checkBoxText && preparedUpdate && updatesAllowed); this._checkBox.actor.checked = (preparedUpdate && updateAlreadyTriggered); + // We show the warning either together with the checkbox, or when + // updates have already been triggered, but the user doesn't have + // enough permissions to cancel them. + this._batteryWarning.visible = (dialogContent.showBatteryWarning && + (this._checkBox.actor.visible || preparedUpdate && updateAlreadyTriggered && !updatesAllowed)); + this._updateButtons(); if (!this.open(timestamp)) {